//DevNETCoder
//CopyRight By DevNET Group
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using STT.Entities;
using STT.DataAccess;
 
namespace STT.Business
{
    public class BTbBacLuong
    {
        public static DataTable Search(ETbBacLuong bl)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaBL", bl.MaBL);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbBacLuong_Search", pr);
            return all;
        }

        public static bool KiemTraDuLieu(ETbBacLuong bl)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaBL", bl.MaBL);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbBacLuong_KiemTraDuLieu", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
//-----------------------------------------------------------//
        public static DataTable SelectAll()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbBacLuong_SelectAll", null);
            return all;
        }
//-----------------------------------------------------------//
        public static void Insert(ETbBacLuong OTbBacLuong)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaBL", OTbBacLuong.MaBL);
            pr[1] = new SqlParameter(@"MoTa", OTbBacLuong.MoTa);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbBacLuong_Insert", pr);
        }
//-----------------------------------------------------------//
        public static void Update(ETbBacLuong OTbBacLuong)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaBL", OTbBacLuong.MaBL);
            pr[1] = new SqlParameter(@"MoTa", OTbBacLuong.MoTa);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbBacLuong_Update", pr);
        }
//-----------------------------------------------------------//
        public static void Delete(string MaBL)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaBL",MaBL);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbBacLuong_Delete", pr);
        }
//-----------------------------------------------------------//
        public static ETbBacLuong SelectByID(string MaBL)
        {
            ETbBacLuong OTbBacLuong = new ETbBacLuong();
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaBL",MaBL);
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure,"TbBacLuong_SelectByID", pr);
            if (idr.Read())
              OTbBacLuong = GetOneTbBacLuong(idr);
            idr.Close();
            idr.Dispose();
            return OTbBacLuong;
        }
//-----------------------------------------------------------//
        private static ETbBacLuong GetOneTbBacLuong(IDataReader idr)
       {
            ETbBacLuong OTbBacLuong = new ETbBacLuong();
                if (idr["MaBL"] != DBNull.Value)
                    OTbBacLuong.MaBL = (string)idr["MaBL"];
                if (idr["MoTa"] != DBNull.Value)
                    OTbBacLuong.MoTa = (string)idr["MoTa"];
            return OTbBacLuong;
       }
//-----------------------------------------------------------//
        public static bool TestByID(string MaBL)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaBL",MaBL);
            pr[1] = new SqlParameter(@"TestID",SqlDbType.Bit);
            pr[1].Direction = ParameterDirection.Output;
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure,"TbBacLuong_TestByID", pr);
            return Convert.ToBoolean(pr[1].Value);
        }
//-----------------------------------------------------------//
        public static List<ETbBacLuong> ListAll()
        {
            List<ETbBacLuong> list = new List<ETbBacLuong>();
            IDataReader idr = SqlHelper.ExecuteReader(CommandType.StoredProcedure, "TbBacLuong_SelectAll", null);
            while (idr.Read())
              list.Add(GetOneTbBacLuong(idr));
            if (idr.IsClosed == false)
            {
               idr.Close();
               idr.Dispose();
            }
            return list;
        }
    }
 
}
